package com.io.nettyflow.serverHandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * Created by yangyx on 2016/7/21.
 */
public class VtChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //把所有的handler放在了此处。
        //设置心跳
        socketChannel.pipeline().addLast(new IdleStateHandler(35,0,0, TimeUnit.SECONDS));
        //编码器   out放在最前面
        socketChannel.pipeline().addLast(VtsencoderHandler.sharedObj());
        //解析传送过来的数据是否正确
        socketChannel.pipeline().addLast(new VtsDecoderHandler());
        //把接受的数据根据逻辑进行处理
        socketChannel.pipeline().addLast(VtChannelHandler.sharedObj());

    }
}
